<template>
	<div class="system-dic-container layout-padding">
		<el-card shadow="hover" class="layout-padding-auto">
			<div class="system-user-search mb15">
				<el-select v-model="state.tableData.param.param.company_id.val" filterable placeholder="请选择所属公司" clearable size="default" style="width: 180px;">
					<el-option v-for="(item,index) in state.platsData.company" :key="item.id" :label="item.title" :value="item.id"></el-option>
				</el-select>
                <el-select v-model="state.tableData.param.param.status.val" placeholder="请选择状态" clearable size="default" style="width: 180px;">
					<el-option label="付款中" value="1"></el-option>
					<el-option label="已付款" value="2"></el-option>
				</el-select>
				<el-button size="default" type="primary"  @click="seachClick">
					<el-icon>
						<ele-Search />
					</el-icon>
					查询
				</el-button>
			</div>
			<el-table :data="state.tableData.data"  v-loading="state.tableData.loading" style="width: 100%">
				<el-table-column prop="id" label="ID" show-overflow-tooltip width="80px"></el-table-column>
				<el-table-column label="月份" show-overflow-tooltip width="120">
					<template #default="scope">
						<span>{{ dateFormatYM(scope.row.m_time * 1000)}}</span>
                    </template>
				</el-table-column>
				<el-table-column prop="order_no" label="账单号" show-overflow-tooltip></el-table-column>
				<el-table-column label="支付方式" show-overflow-tooltip>
					<template #default="scope">
						{{ state.payData[scope.row.payment] || '未知方式' }}
					</template>
                </el-table-column>
				<el-table-column prop="pay_username" label="收款账号" show-overflow-tooltip></el-table-column>
				<el-table-column label="类型" show-overflow-tooltip>
                    <template #default="scope">
						<el-tag>{{ scope.row.user_id > 0 ? '个人' : '公司'}}</el-tag>
					</template>
                </el-table-column>
                <el-table-column label="公司名 / 个人昵称" show-overflow-tooltip>
                    <template #default="scope">
						{{ scope.row.name }}
					</template>
                </el-table-column>
                <el-table-column prop="pay" label="付款积分"  width="150px">
                    <template #default="scope">
						<span :style="{color:scope.row.status == 1?'#67C23A':scope.row.status == 2?'#F56C6C':'#000'}">{{scope.row.pay}}</span>
					</template>
                </el-table-column>
				<el-table-column label="状态" show-overflow-tooltip width="150px">
					<template #default="scope" >
                        <div class="xiaojiujiudiv">
                            <div class="xiaojiujiu" :style="{backgroundColor:scope.row.status == 1?'#E6A23C':'#67C23A'}"></div>
                            <span v-if="scope.row.status == 1">付款中</span>
                            <span v-else>已付款</span>
                        </div>
					</template>
				</el-table-column>
				<!-- <el-table-column label="完成时间" width="180px">
					<template #default="scope">
						<span>{{ dateFormatYMDHMS(scope.row.create_time * 1000)}}</span>
                    </template>
				</el-table-column> -->
				<el-table-column label="操作" width="80">
					<template #default="scope">
						<el-button size="small" text type="primary" v-auth="'/finance/remit/edit'"  @click="onOpenEdit(scope.row)">修改</el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				@size-change="onHandleSizeChange"
				@current-change="onHandleCurrentChange"
				class="mt15"
				:pager-count="5"
				:page-sizes="[10, 50, 100]"
				v-model:current-page="state.tableData.param.page"
				background
				v-model:page-size="state.tableData.param.limit"
				layout="total, sizes, prev, pager, next, jumper"
				:total="state.tableData.total"
			>
			</el-pagination>
		</el-card>
		<editDialog ref="editDialogRef" @refresh="getTableData()" />
	</div>
</template>

<script setup name="record">
import { defineAsyncComponent, reactive, onMounted, ref } from 'vue';
import { remitApi } from '/@/api/remit/index';
import commonFunction from '/@/utils/commonFunction';
const editDialog = defineAsyncComponent(() => import('./dialog.vue'));
// 定义变量内容
const { dateFormatYMDHMS,dateFormatYM } = commonFunction();
import { commApi } from '/@/api/comm/index';
const paramOp = {
}
// 定义变量内容
const editDialogRef = ref();
const state = reactive({
	payData:{
		// 1:'微信',
		// 2:'支付宝',
		// 3:'银行卡',
		4:'Paypal',
    },
	platsData:{
		company:[],
	},
	tableData: {
		total_money:0,
		data: [],
		total: 0,
		loading: false,
		param: {
			param:{
				company_id:{},
				status:{}
			},
			page: 1,
			limit: 10,
		},
	},
});
const getPlats = () => {
	commApi().getPlats().then(res=>{
		state.platsData = res.data
	})
}
// 初始化表格数据
const getTableData = () => {
	state.tableData.loading = true;
	for (let key in state.tableData.param.param) {
		if (state.tableData.param.param[key].val && state.tableData.param.param[key].val !== '') {
			state.tableData.param.param[key].op = paramOp[key] || '='
		}else{
			state.tableData.param.param[key] = {}
		}
	}
    remitApi().index(state.tableData.param).then(res=>{
        state.tableData.data = res.data.list;
        state.tableData.total = res.data.total;
        state.tableData.loading = false;
		state.tableData.total_money = res.data.total_pay;
    })
};
// 打开编辑弹窗
const onOpenEdit = (row) =>{
	editDialogRef.value.openDialog(row);
}

const seachClick = () =>{
	onHandleCurrentChange(1)
}
// 分页改变
const onHandleSizeChange = (val) => {
	state.tableData.param.limit = val;
	getTableData();
};
// 分页改变
const onHandleCurrentChange = (val) => {
	state.tableData.param.page = val;
	getTableData();
};
// 页面加载时
onMounted(() => {
	getTableData();
	getPlats();
});
</script>
<style lang="scss" scoped>
.xiaojiujiudiv{
    width: 100%;
    display: flex;
    align-items: center;
    .xiaojiujiu{
        width: 10px;
        height: 10px;
        border-radius: 50%;
        margin-right: 5px;
        flex: none;
    }
    span{
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}
</style>
